package com.gyg.controller;


import com.gyg.client.CloudTrashClient;
import com.gyg.domain.CloudUser;
import com.gyg.enums.SessionEnum;
import com.gyg.returns.RespEntity;
import com.gyg.vo.param.TrashParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 文件回收表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/cloud-trash")
@Slf4j
@Api(value = "文件回收站", tags = "文件回收站")
public class CloudTrashController {

    @Resource
    private CloudTrashClient cloudTrashClient;

    @ApiOperation(value = "操作记录列表")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNum", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页数量", required = true)
    })
    public RespEntity cloudTrashList(@RequestParam(value = "pageNum", required = true) Integer pageNum,
                                      @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                      HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        RespEntity respEntity = cloudTrashClient.cloudTrashList(cloudUser.getId(), pageNum, pageSize);
        return respEntity;
    }

    @PutMapping("/recover")
    @ApiOperation(value = "恢复")
    public RespEntity recoverTrash(TrashParam trashParam, HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        trashParam.setUserId(cloudUser.getId());
        RespEntity respEntity = cloudTrashClient.recoverTrash(trashParam);
        return respEntity;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "彻底删除")
    public RespEntity deleteTrash(TrashParam trashParam, HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        trashParam.setUserId(cloudUser.getId());
        RespEntity respEntity = cloudTrashClient.deleteTrash(trashParam);
        return respEntity;
    }
}
